using Common.Commands.AccountCommands;
using Common.Enumerations;
using Core.Domain.Model;
using NUnit.Framework;
using Sanelib.Common.Extensions;
using Sanelib.Common.Helpers;
using WebApp.ModelService;

namespace IntegrationTests.ModelServices
{
    public class AccountModelServiceTester : IntegrationTestBase
    {
        [Test]
        public void ShouldGetById()
        {
            var account = new Account
            {
                Id = GuidComb.New(),
                Name = "Priya",
                AccountType = AccountType.Vendor,
                AccountNumber = "accountnumber",
                Industry = Industry.InternetPublishing,
                BillingStreet = "billingstreet",
                BillingCity = "city",
                BillingState = "state",
                BillingPostalCode = "code",
                BillingCountry = "county",
                BillingLatitude = 0,
                BillingLongitude = 0,
                ShippingStreet = "sstreet",
                ShippingCity = "scity",
                ShippingState = "sstate",
                ShippingPostalCode = "Scode",
                ShippingCountry = "scountry",
                ShippingLatitude = 0,
                ShippingLongitude = 0,
                Phone = "phone",
                Mobile = "mobile",
                Fax = "fax",
                Website = "web",
                Email = "email@email.com",
                Description = "Description",
                ImageData = ImageUtility.NoImageData
            };

            Persist(account);

            var accountModelService = GetInstance<IAccountModelService>();
            var response = accountModelService.GetAccountDetailById(account.Id);

            Assert.AreEqual(response.Detail.Id, account.Id);
        }

        [Test]
        public void ShouldGetByIdForEdit()
        {
            var account = new Account
            {
                Id = GuidComb.New(),
                Name = "Priya",
                AccountType = AccountType.Vendor,
                AccountNumber = "accountnumber",
                Industry = Industry.InternetPublishing,
                BillingStreet = "billingstreet",
                BillingCity = "city",
                BillingState = "state",
                BillingPostalCode = "code",
                BillingCountry = "county",
                BillingLatitude = 0,
                BillingLongitude = 0,
                ShippingStreet = "sstreet",
                ShippingCity = "scity",
                ShippingState = "sstate",
                ShippingPostalCode = "Scode",
                ShippingCountry = "scountry",
                ShippingLatitude = 0,
                ShippingLongitude = 0,
                Phone = "phone",
                Mobile = "mobile",
                Fax = "fax",
                Website = "web",
                Email = "email@email.com",
                Description = "Description",
                ImageData = ImageUtility.NoImageData
            };

            Persist(account);

            var command = new UpdateAccount
            {
                Id = account.Id,
                Name = "PRincy",
                AccountType = AccountType.Vendor,
                AccountNumber = "accountnumber",
                Industry = Industry.Banking,
                BillingStreet = "billingstreet",
                BillingCity = "city",
                BillingState = "state",
                BillingPostalCode = "code",
                BillingCountry = "county",
                ShippingStreet = "sstreet",
                ShippingCity = "scity",
                ShippingState = "sstate",
                ShippingPostalCode = "Scode",
                ShippingCountry = "scountry",
                Phone = "phone",
                Mobile = "mobile",
                Fax = "fax",
                Website = "web",
                Email = "email@email.com",
                Description = "description",
                ImageData = ImageUtility.NoImageData
            };
            ProcessCommand(command);

            var accountModelService = GetInstance<IAccountModelService>();
            var response = accountModelService.GetAccountDetailById(command.Id);

            Assert.AreEqual(response.Detail.Id, account.Id);
        }

        [Test]
        public void ShouldTestGetDetailById()
        {
            var member = GetSiteUser();

            var account = new Account
            {
                Id = GuidComb.New(),
                Name = "Priya",
                AccountType = AccountType.Vendor,
                AccountNumber = "accountnumber",
                Industry = Industry.InternetPublishing,
                BillingStreet = "billingstreet",
                BillingCity = "city",
                BillingState = "state",
                BillingPostalCode = "code",
                BillingCountry = "county",
                BillingLatitude = 0,
                BillingLongitude = 0,
                ShippingStreet = "sstreet",
                ShippingCity = "scity",
                ShippingState = "sstate",
                ShippingPostalCode = "Scode",
                ShippingCountry = "scountry",
                ShippingLatitude = 0,
                ShippingLongitude = 0,
                Phone = "phone",
                Mobile = "mobile",
                Fax = "fax",
                Website = "web",
                Email = "email@email.com",
                Description = "Description",
                ImageData = ImageUtility.NoImageData
            };

            var contact = new Contact
            {
                Id = GuidComb.New(),
                Name = "NikunjBBalar",
                NameTitle = NameTitle.Mr,
                LastName = "Nikunj",
                FirstName = "Balar",
                Email = "niksunjbbalar@gmail.com",
                Phone = "9099791517",
                Mobile = "9099791517",
                CompanyName = "Sanelib Software Solutions",
                Designation = Designation.De,
                Description = "With 1 yeat experiance in c#. net MVC",
                ImageData = ImageUtility.NoImageData
            };

            var assignedContact = new AssignedContact
            {
                Id = GuidComb.New(),
                Name = "Assign Contact Name",
                ContactId = contact.Id,
                Description = "Case for finance",
                ReferenceId = account.Id,
                ReferenceName = account.Name,
                EntityType = EntityType.Account,
                CreatedBy = member.Id
            };

            var note = new Note
            {
                Id = GuidComb.New(),
                Name = "Note Name",
                EntityType = EntityType.Account,
                ReferenceId = account.Id,
                ReferenceName = "AC",
                Description = "Finance Account"
            };

            var attachment = new Attachment
            {
                Id = GuidComb.New(),
                Name = "SanelibAccounts",
                FileType = "image/png",
                FileSize = 10,
                FileHashCode = "gsdhf35989fsnl1324ywefnj",
                ImageData = ImageUtility.NoImageData,
                EntityType = EntityType.Account,
                ReferenceId = account.Id,
                ReferenceName = "AC",
                Description = "This file for Account of sanelib"
            };

            Persist(member, account, contact, assignedContact, note, attachment);

            var accountModelService = GetInstance<IAccountModelService>();

            var response = accountModelService.GetAccountDetailById(account.Id);

            Assert.AreEqual(response.Detail.Id, account.Id);
            Assert.AreEqual(response.ContactLines[0].ContactId, assignedContact.ContactId);
            Assert.AreEqual(response.Notes[0].Id, note.Id);
            Assert.AreEqual(response.Attachments[0].Id, attachment.Id);
        }
    }
}